// pages/member/activation.js
import config from "../../config.js";
var util = require('../../utils/util.js');
const openIdUrl = config;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user: null,
    isMember: false,
    isMemberBind: false,
    isMember99Ship: false,
    member: {},
    card: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var user = wx.getStorageSync('user');
    this.setData({
      user: user
    })

    if (user.isMemberShip == 1) {
      this.setData({
        isMember: true
      })
    } else {
      this.setData({
        isMember: false
      })
    }

    if (user.isMemberBind == 1) {
      this.setData({
        isMemberBind: true
      })
    } else {
      this.setData({
        isMemberBind: false
      })
    }
    if (user.isMember99Ship == 1) {
      this.setData({
        isMember99Ship: true
      })
    } else {
      this.setData({
        isMember99Ship: false
      })
    }

    this.loadData();
  },
  loadData: function() {
    var that = this
    wx.showLoading({
      title: '信息获取中...',
    })
    wx.request({
      url: openIdUrl.getSystemInfo,
      data: {},
      success: function(result) {
        console.log(result);
        wx.hideLoading();
        if (result.data.status == 200) {
          that.setData({
            member: result.data.data
          })
        }
      }
    })
  },
  loadMemberCardData: function() {
    var that = this
    wx.request({
      url: openIdUrl.getCurrentMemberCardList,
      data: {},
      success: function(result) {
        console.log(result);
        wx.hideLoading();
        if (result.data.status == 200) {
          that.setData({
            card: result.data.data[0]
          })

          wx.setStorageSync("membercard", result.data.data[0]);
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.loadMemberCardData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  activaeAction: function(e) {
    var type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: './memberRight?type=' + type,
    })
  },
  bindAction: function() {
    wx.scanCode({
      scanType: ['scanType', 'qrCode', 'datamatrix', 'pdf417'],
      success: function(res) {
        console.log(res);
        wx.navigateTo({
          url: './confirm?id=' + res.result,
        })
      }
    })
  }
})